package com.huluobo.h3kotlinproject.category

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.huluobo.h3kotlinproject.R
import com.huluobo.h3kotlinproject.databinding.ItemCategoryParentBinding

/**
 *  Created by LC on 2023/10/27.
 */
class CategoryParentAdapter(list: MutableList<CategoryBean>) :
    BaseQuickAdapter<CategoryBean, CategoryParentAdapter.CategoryViewHolder>(R.layout.item_category_parent, list) {

    private var selectItemId: Int = 1
    override fun convert(holder: CategoryViewHolder, item: CategoryBean) {
        holder.itemDataBinding.category = item

        holder.itemDataBinding.categoryParentItemCl.background =
            if (item.id == selectItemId) ColorDrawable(Color.LTGRAY) else null
    }

    override fun createBaseViewHolder(parent: ViewGroup, layoutResId: Int): CategoryViewHolder {
        val itemDataBinding = ItemCategoryParentBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return CategoryViewHolder(itemDataBinding)
    }

    //设置选中的ItemId
    fun setSelectItemPosition(itemId: Int) {
        selectItemId = itemId
        notifyDataSetChanged()
    }

    class CategoryViewHolder(var itemDataBinding: ItemCategoryParentBinding) : BaseViewHolder(itemDataBinding.root)
}